Thanks i´ll try it out within a couple of hours when i get back home.
::edit::
I just tried to do what you suggested.
Heres the code i changed - the myButton region
Code:
#region My own button creations
private void initMyButtons() {
//initialise every button
for(int y=0;y<World.HEIGHT-2;y++){
for(int x=0;x<World.WIDTH-2;x++){
this.defaultButton[y][x] = new Button();
}
}
for(int y=0;y<World.HEIGHT-2;y++){
for(int x=0;x<World.WIDTH-2;x++){
this.defaultButton[y][x].set_Location(new System.Drawing.Point((20+(20*y)),((20*x)+20)));
this.defaultButton[y][x].set_Name(""+y+x);
this.defaultButton[y][x].set_Size(new System.Drawing.Size(20, 20));
this.defaultButton[y][x].set_TabIndex(1);
this.defaultButton[x][y].add_Click( new System.EventHandler(this.showValue(defaultButton[x][y],y,x)) ); //THE LINE I ADDED
this.get_Controls().Add(this.defaultButton[y][x]);
}
}
}
#endregion
Then i have in the same class this handler - or what i think that can go trough as handler....
Code:
//Event handler for the playfield
private void showValue(Button defaultButton[][],int y, int x) {
defaultButton[y][x].set_Text(""+w.wereld[y+1][x+1]);
}
Visual studio is giving me these compiler errors:
The argument in the creation of delegate 'System.EventHandler' must name a method.
This error points to the line I added when creating these buttons, so to this line
Code:
this.defaultButton[x][y].add_Click( new System.EventHandler(this.showValue(defaultButton[x][y],y,x)) );
I googled on msdn library for the explanation on delegates and found this .
But I dont see how something like that would resolve my problem and if it did how to implement something like that... I´ve never heard of delegates before so im kind of lost right now on how i should handle this.
I was even thinking about this just some minutes ago.
Suppose i create my own Class called Mybuttons, that class will only exists of a copy constructor wich will take a default button Object, placed in the visual studio designer method as an argument, then takes y and x as arguments as well....
Then it´ll copy all the properties - and also the eventHandler that is assigned to the default button which i created in the visual studio designer...
After that i would easily be able to change the eventHandler that is generated by visual studio for my designer method created button , thereby also changing the event handler for every other button i would create using my Mybuttons class...
I was wondering wether something like this would work as well and without using delegates...
I´m just guessing actually since i dont have a clue again ...
Any adittional information on delegates or a possible way to solve this problem without using these delegates would be appreciated .
::edit 2 ::
Im going to grab a book on C# from someone now, he says it explains delegates etc so i hope to be back in businnes after reading the part about delegates....
::edit 3 ::
I was able to figure things out on a strange way and actually its not really efficient but it does works...
Code:
//at the beginnning of the class
delegate void showValue(Object sender, System.EventArgs e);
//where i give the buttons there property
this.defaultButton[x][y].add_Click( new System.EventHandler(this.showValue) );
//Event handler for the playfield buttons
private void showValue (Object sender, System.EventArgs e){
for(int y=0;y<World.HEIGHT-2;y++){
for(int x=0;x<World.WIDTH-2;x++){
if(sender.equals(defaultButton[y][x])){
defaultButton[y][x].set_Text(""+w.wereld[y][x]);
}
}
}
Is the event handler i am using now
Greetings,
Ganglylamb.
PS: sorry for the bad indentation - it seems everything is alright as long as i dont edit my code while typing it down here in the form to edit my post.